package com.marvels.financial.sms.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fintech.third.model.message.SmsSend;
import com.marvels.common.utils.DateUtils;
import com.marvels.financial.sms.dao.PaymentCategorySmsMapper;
import com.marvels.financial.sms.service.PaymentCategorySmsService;

@Service
public class PaymentCategorySmsImpl implements PaymentCategorySmsService {

	@Autowired
	private PaymentCategorySmsMapper paymentCategorySmsMapper;

	@Override
	public void withholdFailureSms() {
		List<Map<String, Object>> list = paymentCategorySmsMapper.selectwithholdFailure();
		if (list != null && list.size() > 0) {
			for (Map<String, Object> map : list) {
				// 查询出短信模板
				String templateContent = paymentCategorySmsMapper.selectSmsTemplate(1l);
				templateContent = templateContent.replace("date", DateUtils.getDateYYYY_MM_DD(new Date()));
				templateContent = templateContent.replace("date", DateUtils.getDateYYYY_MM_DD(new Date()));
				templateContent = templateContent.replace("bankName", String.valueOf(map.get("bankName")));
				templateContent = templateContent.replace("bankNum4", String.valueOf(map.get("bankCardNo")));
				templateContent = templateContent.replace("amount", String.valueOf(map.get("amount")));
				SmsSend smsSend = new SmsSend();
				smsSend.setPhone(String.valueOf(map.get("mobileNo")));
				smsSend.setMsg(templateContent);
				smsSend.setCreate_time(DateUtils.getDateYYYYMMDDHHMMSS(new Date()));
				smsSend.setSrc(null);
				smsSend.setTemplate_id(1l);
				smsSend.setSend_time(null);
				smsSend.setTiming_send_time(new Date());
				smsSend.setSend_status("0");
				smsSend.setCount(0);
				paymentCategorySmsMapper.insertSmsSend(smsSend);
			}
		}
		// paymentCategorySmsMapper.withholdFailureSms();
	}

	@Override
	public void repaymentReminderSms() {
		List<Map<String, Object>> list = paymentCategorySmsMapper.selectPaymentInfo();
		if (list != null && list.size() > 0) {
			for (Map<String, Object> map : list) {
				// 查询出短信模板
				String templateContent = paymentCategorySmsMapper.selectSmsTemplate(2l);
				templateContent = templateContent.replace("date", DateUtils.getDateYYYY_MM_DD(new Date()));
				templateContent = templateContent.replace("day", String.valueOf(map.get("paymentDate")));
				templateContent = templateContent.replace("amount", String.valueOf(map.get("paymentAmount")));
				templateContent = templateContent.replace("digitsNumber", String.valueOf(map.get("paymentAcctNo")));
				templateContent = templateContent.replace("bankCard", String.valueOf(map.get("paymentBankName")));
				SmsSend smsSend = new SmsSend();
				smsSend.setPhone(String.valueOf(map.get("custMobile")));
				smsSend.setMsg(templateContent);
				smsSend.setSrc(null);
				smsSend.setCreate_time(DateUtils.getDateYYYYMMDDHHMMSS(new Date()));
				smsSend.setTemplate_id(2l);
				smsSend.setSend_time(null);
				smsSend.setTiming_send_time(new Date());
				smsSend.setSend_status("0");
				smsSend.setCount(0);
				paymentCategorySmsMapper.insertSmsSend(smsSend);
			}
		}
		// paymentCategorySmsMapper.repaymentReminderSms();
	}

}
